package com.jerry.passenger;

import android.app.Application;

import com.jerry.passenger.common.http.api.API;
import com.jerry.passenger.common.storage.SPDao;

import cn.bmob.push.BmobPush;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobInstallation;

/**
 * Created by jerrywang on 2018/4/22.
 */
public class MyApplication extends Application {

    private static MyApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance  = this;

        initPush();
    }

    public static MyApplication getInstance() {
        return  instance;
    }

    // 推送服务
    private void initPush() {
        // 初始化BmobSDK
        Bmob.initialize(this, API.Config.getAppId());
        // 使用推送服务时的初始化操作
        BmobInstallation installation = BmobInstallation.getCurrentInstallation(this);
        installation.save();
        String mPushKey = installation.getInstallationId();
        System.out.println("pushKey=" + mPushKey);
        SPDao sharedPreferencesDao = new SPDao(this, SPDao.FILE_ACCOUNT);
        sharedPreferencesDao.save(SPDao.KEY_PUSHKEY, mPushKey);

        // 启动推送服务
        BmobPush.startWork(this);
    }
}
